<?php
header("Content-type:text/html; charset=utf-8;");
require '../../../ppf/fun.php';
require '../../../ppf/pdo_mysql.php';
require '../../../ppf/Filter.php';
date_default_timezone_set("PRC");
$pd=new pdo_mysql();
$filter=new Filter();
session_start();
if(empty($_SESSION['uid'])){
	echo '请登录后再进行操作';exit;
}
$submitMethod=$_SERVER["REQUEST_METHOD"];
if($submitMethod=='POST'){
	$id = empty($_POST['id'])?"":$_POST['id'];
    $now=date('Y-m-d H:i:s',time());
    $title = empty($_POST['title'])?"":$_POST['title'];
    $content = empty($_POST['content'])?"":$_POST['content'];
	$type = empty($_POST['type'])?1:$_POST['type'];
	$start = empty($_POST['start'])?date('Y-m-d',time()):$_POST['start'];//开始时间为空即为立即生效
	$end = empty($_POST['end'])?"":$_POST['end'];//结束时间为空即为手动终止
	if(!$id){
		$rs = $pd->exec("insert into sys_schedule(uid,title,content,type,start,end,time) values(
											'".$_SESSION['uid']."',
											'".$title."',
											'".$content."',
											'".$type."',
											'".$start."',
											'".$end."',
											'".$now."'
			)");
		if($rs){
			$tips='新建日程事务成功';
		}else{
			$tips='新建日程事务失败，请重试';
		}
		echo $tips;exit;
	}else{
		$rs = $pd->exec("update sys_schedule set 
			title='".$title."',
			content='".$content."',
			type='".$type."',
			start='".$start."',
			end='".$end."',
			time='".$now."' where id=".$id);
		if($rs){
			$tips='更新日程事务成功';
		}else{
			$tips='更新日程事务失败，请重试';
		}
		echo $tips;exit;
	}
	
}else{
	echo '不允许的表单提交方式，请按正常流程提交表单。';exit;
}
?>